package com.Babysleep.Activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.SlidingDrawer;

import com.Babysleep.R;

public class Main extends Activity {
	/** Called when the activity is first created. */
	/*
	 * 
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		SharedPreferences settings = getSharedPreferences("settings", 0);
		boolean init = settings.getBoolean("init", false);
		if (!init) {
			SharedPreferences.Editor editor = settings.edit();
			editor.putBoolean("init", true);

			editor.commit();
		} else {
			SlidingDrawer mSlidingDrawer = (SlidingDrawer) this
					.findViewById(R.id.SlidingDrawer);
			mSlidingDrawer.open();
		}
		more_onclick((ImageButton) findViewById(R.id.go_to_more));
		findViewById(R.id.mamashuo).setOnClickListener(new Listener());
		findViewById(R.id.baizaoyin).setOnClickListener(new Listener());
		findViewById(R.id.yudi).setOnClickListener(new Listener());
		findViewById(R.id.hailang).setOnClickListener(new Listener());
		findViewById(R.id.yaolan).setOnClickListener(new Listener());
	}

	protected void onResume() {
		super.onResume();
		slide_drawer_listener((SlidingDrawer) this
				.findViewById(R.id.SlidingDrawer));

	}

	/**
	 * 点击more按钮时的效果
	 */
	public void more_onclick(ImageButton button) {
		button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (v.getId() == R.id.go_to_more)
					System.out.println(v.getId());
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), More.class);
				startActivity(intent);
			}
		});
	}

	/**
	 * 重写抽屉效果
	 */
	public void slide_drawer_listener(SlidingDrawer mSlidingDrawer) {

		mSlidingDrawer
				.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
					@Override
					public void onDrawerOpened() {

					}

				});
		mSlidingDrawer
				.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {

					@Override
					public void onDrawerClosed() {

					}

				});
	}

	/**
	 * 跳转至摇篮曲，沙沙声，妈妈说等内容。
	 */
	class Listener implements OnClickListener {

		@Override
		public void onClick(View v) {
			Intent intent;
			switch (v.getId()) {
			case R.id.yaolan:
				intent = new Intent(getApplicationContext(), YaoLanQu.class);
				intent.putExtra("name", 0);
				startActivity(intent);
				break;
			case R.id.hailang:
				intent = new Intent(getApplicationContext(), DanQu.class);
				intent.putExtra("string_id", R.string.hailang);
				intent.putExtra("name", 1);
				startActivity(intent);
				break;
			case R.id.yudi:
				intent = new Intent(getApplicationContext(), DanQu.class);
				intent.putExtra("string_id", R.string.yudi);
				intent.putExtra("name", 2);
				startActivity(intent);
				break;
			case R.id.baizaoyin:
				intent = new Intent(getApplicationContext(), DanQu.class);
				intent.putExtra("string_id", R.string.baizaoyin);
				intent.putExtra("name", 3);
				startActivity(intent);
				break;

			case R.id.mamashuo:
				intent = new Intent(getApplicationContext(), MaMaShuo.class);
				intent.putExtra("name", 4);
				startActivity(intent);
				break;

			default:
				break;
			}
		}

	}


}